import React from 'react';
import { Form, DatePicker, Select, Button, Table } from 'antd';
import moment from 'moment';
import { connect } from 'dva';
import UserSession from '@/UserSession';
import { formatMessage } from 'umi-plugin-react/locale';

const { RangePicker } = DatePicker;

class CategoryDetailStatistics extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      list: [],
      total: 0,
      loading: true
    }
  }

  componentDidMount() {
    if (this.props.onRef) {
      this.props.onRef(this);
    }
  }

  /**
   * 获取表格数据
   */
  getList = () => {
    const { dispatch, robotId, queryData } = this.props;
    this.setState({ loading: true }, () => {
      const currentUser = UserSession.getCurrentUser()
      if(currentUser.applicationId){
        queryData.applicationId = currentUser.applicationId
      }
      dispatch({
        type: 'qaAnswerStatistics/fetchQaCategoryStatistics',
        payload: queryData,
        callback: (res) => {
          console.log(res);
          this.setState({
            loading: false,
            list: res
          })
        }
      });
    })
  }

  /**
   * 导出
   * @returns {*}
   */
  exportCategoryRecords = () => {
    const { dispatch, queryData } = this.props;
    dispatch({
      type: 'qaAnswerStatistics/exportQaCategoryRecords',
      payload: queryData,
      callback: res => {

      },
    })
  }

  render() {
    const { getFieldDecorator } = this.props.form;
    const { list, loading } = this.state;
    const columns = [
      {
        title: formatMessage({ id: 'categoryStatistics.knowledgeBaseCategory' }),
        dataIndex: 'name',
        key: 'name',
        width: 400
      },
      {
        title: formatMessage({ id: 'categoryStatistics.hitCount' }),
        dataIndex: 'hit',
        key: 'hit',
        width: 200
      },
      {
        title: formatMessage({ id: 'categoryStatistics.unsolvedCount' }),
        dataIndex: 'unsolved',
        width: 200,
        key: 'unsolved',
      },
      {
        title: formatMessage({ id: 'categoryStatistics.unsolvedRatio' }),
        dataIndex: 'ratio',
        width: 200,
        key: 'ratio',
      },
    ];
    return (
      <div>
        <div style={{ width: '100%', textAlign: 'right', marginBottom: 10 }}>
          {/*<Form layout={'inline'}>*/}
          {/*  <Form.Item style={{textAlign:'center'}}>*/}
          {/*    {*/}
          {/*      getFieldDecorator('time',{initialValue:[moment().subtract('7','days'),moment()]})(*/}
          {/*        <RangePicker allowClear={false} />*/}
          {/*      )*/}
          {/*    }*/}
          {/*  </Form.Item>*/}
          {/*  <Form.Item>*/}
          {/*    {*/}
          {/*      getFieldDecorator('trigger',{*/}
          {/*        initialValue:0*/}
          {/*      })(*/}
          {/*        <Select style={{width:200}} placeholder={formatMessage({ id: 'categoryStatistics.selectTriggerMethod' })}>*/}
          {/*          <Select.Option value={0}>{formatMessage({ id: 'categoryStatistics.allTriggerMethods' })}</Select.Option>*/}
          {/*          <Select.Option value={2}>{formatMessage({ id: 'categoryStatistics.clickTrigger' })}</Select.Option>*/}
          {/*          <Select.Option value={1}>{formatMessage({ id: 'categoryStatistics.inputTrigger' })}</Select.Option>*/}
          {/*        </Select>*/}
          {/*      )*/}
          {/*    }*/}
          {/*  </Form.Item>*/}
          {/*  <Form.Item>*/}
          {/*    <Button type={'primary'} onClick={this.queryByConditions}>{formatMessage({ id: 'categoryStatistics.view' })}</Button>*/}
          {/*  </Form.Item>*/}
          {/*  <Form.Item>*/}
          {/*    <Button onClick={this.exportCategoryRecords}>{formatMessage({ id: 'categoryStatistics.download' })}</Button>*/}
          {/*  </Form.Item>*/}
          {/*</Form>*/}
        </div>
        <Table
          dataSource={list}
          columns={columns}
          loading={loading}
          pagination={false}
          rowKey={'id'}
          scroll={{x:"auto"}}
        />
      </div>
    );
  }
}

export default connect(({ user }) => ({ // 全局数据
  currentUser: user.currentUser,
}))(Form.create()(CategoryDetailStatistics));
